<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>修改房间信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <script type="text/javascript" src="/js/cookie.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form" id="update">
        <div class="layui-form-item">
            <label for="roomNumber" class="layui-form-label">
                房间门号
            </label>
            <div class="layui-input-inline">
                <input type="number" id="roomNumber" name="roomNumber" required=""
                       autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="roomType" class="layui-form-label">
                房间类型
            </label>
            <div class="layui-input-inline">
                <select id="roomType" name="rtid">

                </select>

            </div>
        </div>
        <div class="layui-form-item">
            <label for="clockRoom" class="layui-form-label">
                钟点房状态
            </label>
            <div class="layui-input-inline">
                <select name="clockRoom" id="clockRoom" class="layui-select-group">
                    <option name="clockStatus" value="0">否</option>
                    <option name="clockStatus" value="1">是</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="clockPrice" class="layui-form-label">
                钟点房价格
            </label>
            <div class="layui-input-inline">
                <input type="number" id="clockPrice" name="clockPrice" required="" lay-verify="required|number"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="curStatus" class="layui-form-label">
                房间状态
            </label>
            <div class="layui-input-inline">
                <select name="curStatus" id="curStatus" class="layui-select-group">
                    <option name="status" value="0">空闲</option>
                    <option name="status" value="1">入住</option>
                    <option name="status" value="2">维修</option>
                    <option name="status" value="3">废弃</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="roomTel" class="layui-form-label">
                客房电话
            </label>
            <div class="layui-input-inline">
                <input type="tel" id="roomTel" name="roomTel" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center">
            <button type="button" class="layui-btn" lay-filter="edit" lay-submit="">
                提交修改
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        var $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;
        //自定义验证规则
        form.verify({
            //验证固定号码是否有误
           roomTel: [/\d{3,4}[-]\d{7}/, "房间固定号码格式有误"]

        });
        var roomType = parent.$('#roomType option').clone();
        console.dir(roomType);
        $('#roomType').append(roomType);
        form.render('select');
        // 获取父窗口中存储的下拉框选中的值
        var select = parent.$("#selectValue").val();
        // console.log(select);
        $("#curStatus option[value = " + select + "]").prop("selected", true);
        // 获取父窗口中存储的钟点房状态下拉框选中的值
        var clockRoom = parent.$("#clockRoomValue").val();
        $("#clockRoom option[value = " + clockRoom + "]").prop("selected", true);
        // 获取父窗口中存储的房间类型下拉框选中的值
        var curRoomType = parent.$("#curRoomType").val();
        if (curRoomType==""){
            curRoomType="empty";
        }
        $("#roomType option[value = " + curRoomType + "]").prop("selected", true);
        //渲染表单中的下拉框！！
        form.render('select');
        //监听提交
        form.on('submit(edit)', function (data) {
            //发异步，把数据提交给后台
            //获取到表单数据
            //data.field为表单中的数据！
            if(data.field.rtid=="empty"){
                layer.alert('房间类型未选择!',{icon:5});
            }
            else {
                $.ajax({
                    url: '/roomDetail/edit',
                    type: 'POST',
                    data: $('#update').serialize(),
                    success: function (res) {
                        console.log($('#update').serialize());
                        if (res.status == 0) {
                            layer.closeAll('loading');
                            layer.load(2);
                            layer.alert("修改成功", {icon: 6}, function () {
                                console.log(parent);
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                                parent.location.reload();
                            });
                        } else {
                            layer.alert("修改失败", {icon: 5})
                        }
                    },
                })
            }
            return false;
        });

    });
</script>

</body>

</html>